#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
    pid_t id=fork();
    if(id==0)
    {
        printf("I am child process:  pid:%d ppid:%d\n",getpid(),getppid());
        sleep(5);
       // int* p=12345;
       // *p=100;//野指针
        exit(123);
    }
    printf("father wait...\n");
    int status=0;
    pid_t ret=waitpid(id,&status,0);//阻塞等待特定子进程
    if(ret>0&&WIFEXITED(status))//成功退出并等待成功
    {
        printf("wait success: wait for id:%d status code:%d\n",ret,WEXITSTATUS(status));
    }
    else if(ret>0)//退出异常
    {
        printf("exit error! status codedump:%d sign:%d\n",(status>>7)&1,status&0x7F);
    }
    return 0;
}
